package com.zhuss.idea.processor;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.idea.idea.DeleteIdeaBo;
import com.zhuss.bean.vo.idea.idea.DetailIdeaVo;
import com.zhuss.idea.db.dao.ext.IdeaDao;
import com.zhuss.idea.db.entity.Idea;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.WpsException;
import com.zhuss.util.JsonUtil;

/**
 * 删除奇思妙想 processor
 * @Author: zhushanshuo
 * @Date: 2019/9/24 19:54
 */
@Component("ideaDelete")
public class IdeaDelete extends AbstractProcessor<Object, DeleteIdeaBo> implements Processor<Object, DeleteIdeaBo> {

    @Autowired
    private IdeaDao ideaDao;
    
    @Autowired
	@Qualifier("ideaRead")
	private IdeaRead ideaRead;
    
    
    /**
     * 校验
     */
	@Override
    public void check(DeleteIdeaBo bo) throws WpsException {
    	
    }
    
    /**
     * 操作方法
     */
    @Override
    public Object process(DeleteIdeaBo param) throws WpsException {
    	Long ideaId = param.getIdeaId();
    	String name = ((DetailIdeaVo) ideaRead.detail(ideaId)).getTitle();
    	
    	Idea record = new Idea();
    	record.setIdeaId(ideaId);
    	record.setDeleted(param.getDeleted());
    	
    	record.setModifierId(param.getConcurrentUserId());
    	record.setModifier(param.getConcurrentUserName());
    	record.setModifyTime(new Date());
    	ideaDao.delete(record);
    	param.setName(name);
        return null;
    }
    
    /**
     * 操作日志
     */
	@Override
	public Object log(DeleteIdeaBo param) throws WpsException {
		OpLog record = new OpLog();
    	record.setMoudle(MoudleEnum.奇思妙想.key());
    	record.setAction(LogActionEnum.奇思妙想删除.key());
    	record.setTargetId(param.getIdeaId());
    	record.setTargetName(param.getName());
    	record.setContent("参数: " + JsonUtil.toJson(param));
    	record.setReason(param.getExceptionReason());
    	
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	log(record);
    	return null;
	}
}
